<template>
  <div :id="id" :class="ns.b()" :style="{ zIndex: zIndex }" @click.self="onClose">
    <div :class="ns.e('container')" :style="{ width }">
      <div :class="ns.b('header')">
        <span :class="ns.be('header', 'title')">{{ title }}</span>
        <span :class="ns.be('header', 'close')" @click="onClose">
          <el-icon size="24">
            <Close />
          </el-icon>
        </span>
      </div>
      <div :class="ns.b('content')">
        <slot name="content">

        </slot>
      </div>
      <div :class="ns.b('bottom')">
        <slot name="bottom">

        </slot>
      </div>
    </div>
  </div>
</template>


<script lang="ts" setup>
import { useNamespace } from '@/hooks';

import { PopupEvent } from '../type';
import { Close } from "@element-plus/icons-vue"
import { DrawerOptions } from './type';

const ns = useNamespace('dialog')

const props = withDefaults(defineProps<DrawerOptions & { zIndex: number, id: string } & PopupEvent>(), {
  width: '30%'
})
const onClose = () => {
  props?.shutDown();
}

</script>

<style lang="scss" scoped>
$ns: dialog;
$dialog-space: 20px;

@include block($ns) {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(1px);
  overflow: auto;

  @include element(container) {
    position: absolute;
    right: 0;
    min-width: 320px;
    height: 100%;
    background-color: var(--bg-color-light1);

    display: flex;
    flex-direction: column;
  }
}

@include block(#{$ns}-content) {
  width: 100%;
  flex: 1;
  padding: $dialog-space;
  box-sizing: border-box;
  overflow: auto;
}

@include block(#{$ns}-bottom) {
  border-top: 0.5px solid var(--bg-color-light6);
  padding: $dialog-space $dialog-space 0 $dialog-space;
  box-sizing: border-box;
  width: 100%;
}

@include block(#{$ns}-header) {
  width: 100%;
  padding: 10px $dialog-space;
  border-bottom: 0.5px solid var(--bg-color-light6);
  box-sizing: border-box;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 3px;

  @include element(title) {
    display: flex;
    align-items: baseline;
    height: 21px;
    line-height: 20px;
    font-weight: bold;
  }

  @include element(close) {
    width: 21px;
    height: 21px;
    line-height: 21px;
    font-weight: normal;
    cursor: pointer;
    color: var(--text-color-regular);

    &:hover {
      color: var(--intent-color-theme);
    }
  }
}
</style>